package com.ikingtech.platform.service.system.post.service;

import com.ikingtech.framework.sdk.user.api.UserPostApi;
import com.ikingtech.framework.sdk.user.model.UserPostDTO;
import com.ikingtech.framework.sdk.utils.Tools;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author tie yan
 */
@Service
@RequiredArgsConstructor
public class UserPostService implements UserPostApi {

    private final PostService service;

    @Override
    public List<UserPostDTO> loadByIds(List<String> postIds) {
        if(Tools.Coll.isBlank(postIds)){
            return new ArrayList<>();
        }
        return Tools.Coll.convertList(this.service.listByIds(postIds), entity -> {
            UserPostDTO userPost = new UserPostDTO();
            userPost.setPostId(entity.getId());
            userPost.setPostName(entity.getName());
            return userPost;
        });
    }
}
